<template>
	<view class="content">
		<heade title="销售订单列表" cross bg_color="bg_fff">
			<text class="iconfont icon-shaixuan f-s20 f-wbold" @tap="screen"></text>
			<text class="iconfont icon-jiahao_o f-s20 m-l5 f-wbold" @tap="$common.url('/pages/parameters/parameters?title=销售订单')"></text>
		</heade>
		<view class="">
			<view class="position-fixed bg_fff p-b10" :style="{'top':$common.headHeight()+44 +'px'}" style="width: 100%;border-bottom: 2rpx solid #F8F8F8;">
				<view class="d-flex align-center justify-content-space-around m-t12 f-s14">
					<!-- 日期 -->
					<view class="d-flex align-center" @tap="show">
						<view v-if="BeginDefault == ''">日期</view>
						<view v-else>{{BeginDefault}} - {{EndDefault}}</view>
						<view class="iconfont icon-sanjiaoxing m-l5 f-s10"></view>
					</view>
				</view>
			</view>
			<view style="height: 94rpx;"></view>
			
			<view class="">
				<view v-for="item in list" class="flex1 d-flex align-center m-t10 justify-content-space-between p-b10 p-r15" style="border-bottom: 2rpx solid #e8e5e5;">
					<view class="flex1 m-l15">
						<view class="d-flex align-center justify-content-space-between">
							<view class="f-s13">{{item.voucherCode}}</view>
							<view class="f-s14 co_F4B41A">{{item.SaleOrderState}}</view>
						</view>
						<view class="d-flex align-center justify-content-space-between m-t5 m-b5 f-wbold">
							<view class="f-s15 webkit-line-clamp-1" style="width: 500rpx;">{{item.address}}</view>
							<view class="f-s14 co_c60001">¥{{item.taxAmount}}</view>
						</view>
						<view class="d-flex align-center justify-content-space-between m-t3 f-s14">
							<view class="webkit-line-clamp-1" style="width: 380rpx;">联系人: {{item.partnerName}}</view>
							<view class="">{{item.voucherdate}}</view>
						</view>	
					</view>
					<!-- <view class="p-l20 " @tap="moreClick">
						<view class="iconfont icon-gengduo co_000 f-s20 f-wbold"></view>
					</view> -->
				</view>
				<uni-load-more v-if="more" :status="status"></uni-load-more>
			</view>
		</view>
		
		<view class="b-liuhai" ><view style="height: 70rpx;"></view></view>
		<view style="position: fixed; bottom: 0;width: 100%;z-index: 9;" class="bg_fff">
			<view class="b-liuhai">
				<view class="bg_FFF8EB p-t10 p-b10 p-l12 flex1">
					<!-- <view class="f-s14">合计: <text class="co_E04C46 f-wbold m-l5">¥{{total}}</text></view> -->
					<view class="d-flex align-center">
						<view class="f-s12">共{{totalCount}}件</view>
						<!-- <view class="f-s14 m-l30">总收款: <text class="co_E04C46 f-wbold m-l5">{{total}}</text></view> -->
					</view>
				</view>
				<!-- <view class="bg_3A8CFF d-flex align-center justify-content-center" style="height: 80rpx;" @tap="submit">
					<view class="co_fff f-s14 f-w400">生单</view>
				</view> -->
			</view>
		</view>
		<wly-datetime-picker type="daterange" ref="wlyDatetime" @change="confirm" :isIcons="false"  />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index:0,
				array:['商品名称','商品编码'],
				list:[],
				total:'0.00',
				dateStatus:0,
				conditionStatus:0,
				dateList:['全部','今天','昨天','本周','本月','上月','本季度','本年'],
				conditionList:['全部','未审','生效'],
				SaleOrderDetails:[],
				Pages:1,
				more:true,
				status:'noMore',
				totalCount:0,
				BeginDefault:'',
				EndDefault:'',
				partnerName:{name:'',code:''},
				SettleCustomer:{name:'',code:''},
			}
		},
		onShow() {
			var pages = getCurrentPages();
			var pages1 = pages[pages.length - 1]
			if(pages1.$vm.timeData) {
				this.BeginDefault = pages1.$vm.timeData[0];
				this.EndDefault =  pages1.$vm.timeData[1]
			}
			if(pages1.$vm.partnerName) {
				this.partnerName = pages1.$vm.partnerName
			}
			if(pages1.$vm.SettleCustomer) {
				this.SettleCustomer = pages1.$vm.SettleCustomer
			}
			this.getData()
		},
		onReachBottom(){
			var _this = this;
		   if(_this.status == 'loading'){
				_this.Pages++
				_this.more=true;
				this.getData()
		   }
		},
		methods: {
			getData() {
				// {
				// 	"ColumnName": "partnerName",
				// 	"BeginDefault": "酒水城",
				// 	"BeginDefaultText": "酒水城",
				// 	"EndDefault": "酒水城",
				// 	"EndDefaultText": "酒水城"
				// },
				
				// {
				// 	"ColumnName": "inventoryName",
				// 	"BeginDefault": "无穷精品盐局鸡翅",
				// 	"BeginDefaultText": "无穷精品盐局鸡翅",
				// 	"EndDefault": "无穷精品盐局鸡翅",
				// 	"EndDefaultText": "无穷精品盐局鸡翅"
				// },
				let SearchItems = []
				// 客户
				if(this.partnerName.code != '' && this.partnerName.name != '') {
					SearchItems.push({
						"ColumnName": "partnerCode",
						"BeginDefault": this.partnerName.code,
						"BeginDefaultText": this.partnerName.code,
						"EndDefault": this.partnerName.code,
						"EndDefaultText": this.partnerName.code
					},
					{
						"ColumnName": "partnerName",
						"BeginDefault": this.partnerName.name,
						"BeginDefaultText": this.partnerName.name,
						"EndDefault": this.partnerName.name,
						"EndDefaultText": this.partnerName.name
					})
				}
				// 结算客户  
				if(this.SettleCustomer.code != '' && this.SettleCustomer.name != '') {
					SearchItems.push({
						"ColumnName": "SettleCustomer",
						"BeginDefault": this.SettleCustomer.name,
						"BeginDefaultText": this.SettleCustomer.name,
						"EndDefault": this.SettleCustomer.name,
						"EndDefaultText": this.SettleCustomer.name
					},
					{
						"ColumnName": "SettleCustomerCode",
						"BeginDefault": this.SettleCustomer.code,
						"BeginDefaultText": this.SettleCustomer.code,
						"EndDefault": this.SettleCustomer.code,
						"EndDefaultText": this.SettleCustomer.code
					})
				}
				let resData = {
					pageIndex:this.Pages,
					pageSize:20,
					SearchItems //查询项；
				}
				// 时间
				if(this.BeginDefault != '' && this.EndDefault != '') {
					resData.beginDate = this.BeginDefault
					resData.endDate = this.EndDefault
				}
				this.$http.post(`ApiSA/GetSaleOrders`,resData).then(res => {
					if(res.statusCode == 200) {
						this.totalCount = res.data.totalCount
						let val = ''
						res.data.dataSource.forEach(e => {
							if(e.voucherdate) {
								val = e.voucherdate.split('T')
								e.voucherdate = val[0]
							}
						})
						if(this.Pages>1){
							this.list = this.list.concat(res.data.dataSource||[])
						}else{
							this.list = res.data.dataSource;
							this.more = false;
							this.status = 'loading'
						}
						if(res.data.dataSource.length==0){
							this.status = 'noMore';
							return;
						}
						this.more= false;
					}
				})
			},
			bindPickerChange(e) {
				this.index = e.detail.value
				if(this.index == 0) {
					this.Code = ''
				}else {
					this.Name = ''
				}
			},
			// 点击筛选
			screen() {
				let body = {}
				if(this.BeginDefault != '') {
					body.BeginDefault = this.BeginDefault
				}
				if(this.EndDefault != '') {
					body.EndDefault = this.EndDefault
				}
				if(this.partnerName.name != '') {
					body.partnerName = this.partnerName
				}
				if(this.SettleCustomer.name != '') {
					body.SettleCustomer = this.SettleCustomer
				}
				if(this.BeginDefault != '' || this.SettleCustomer.name != '' || this.partnerName.name != '') {
					this.$common.url('/pages/salesOrderList/advanced?body='+JSON.stringify(body))
				}else {
					this.$common.url('/pages/salesOrderList/advanced')
				}
			},
			// 点击更多
			moreClick() {
				uni.showActionSheet({ 	
					itemList: ['复制', '删除'],
					success: function (res) {
						console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
			// 日期选择
			dateChange(e) {
				this.dateStatus = e.detail.value	
			},
			show() {
				this.$refs.wlyDatetime.show()
			},
			confirm(e) {
				if(this.BeginDefault == e[0] &&this.EndDefault == e[1]) {
					this.BeginDefault = '';
					this.EndDefault =  ''
				}else {
					this.BeginDefault = e[0];
					this.EndDefault =  e[1]
				}
				this.Pages = 1
				this.getData()
			},
			//状态选择
			conditionChange(e) {
				this.conditionStatus = e.detail.value	
			},
			submit() {
				// this.$refs.wlyDatetime.show()
			}
		}
	}
</script>

<style lang="scss">
	.sousuo {
		height: 56rpx;
		border-radius: 56rpx;
		background: #f3f2f7;
	}
</style>